<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [1, 2, 3, 4, 1, 2, 3, 4, 1, 1, 1];
        let res = [...new Set(arr)];
        let res1 = Array.from(new Set(arr));
        console.log(res, res1);

        // 1. Array.from 方法是构造函数的方法 把类数组变成真正的数组

        let colors = ["red", "green", "blue", "yellow", "purple"];
        // let colors2 = colors.slice(1);
        // let colors3 = colors.slice(1, 4);
        // console.log(colors);
        // console.log(colors2);
        // console.log(colors3);
        // let colors2 = colors.splice(1, 2);
        // console.log(colors, colors2);
        // let colors3 = colors.splice(1, 0, "aaa");
        let colors4 = colors.splice(3, 2, "aaa", "bbb", "ccc");
        console.log(colors, colors4);

        let arr2 = [1, 2, 3];
        let res2 = arr2.map((i) => i * 2);
        console.log(arr2, res2);

        let numbers = [{
            a: 1,
        }, {
            a: 2,
        }, {
            a: 3,
        }, {
            a: 4,
        }, {
            a: 5,
        }, ];

        let numbers2 = numbers.map((item, index, array) => {
            // console.log(item, index, array);
            // return item.a * 3;
            if (index <= 2) {
                return item.a * 3;
            } else {
                return item.a * 2;
            }
        });
        console.log(numbers2);

        let str = [{
            a: 1,
        }, {
            a: 2,
        }, ].join(",");
        console.log(str);

        let persons = [{
            age: 50,
        }, {
            age: 12,
        }, {
            age: 30,
        }, ];
        //请写一个方法将persons变为 '12,30,50'

        let obj = persons.sort((a, b) => {
            return a.age - b.age;
        });
        // persons.map()
        let num = obj.map((i) => {
            return i.age;
        });
        let num01 = num.join(",");
        console.log(num01);

        let a = 10,
            b = 20;
        [a, b] = [b, a];
    </script>
</body>

</html>